using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace VGS
{
    class PlayerRadioButton : RadioButton
    {
        private Player player = null; // Initialize to null
        private ToolTip tooltip = new ToolTip();

        public PlayerRadioButton()
        {
            // Initialize the control
            base.FlatStyle = FlatStyle.Flat;
            base.Appearance = Appearance.Button;
            base.FlatAppearance.BorderSize = 1;
            base.FlatAppearance.BorderColor = Color.Black;
            base.FlatAppearance.CheckedBackColor = Color.Orange;
            base.FlatAppearance.MouseDownBackColor = Color.FromKnownColor(KnownColor.Control);
            base.FlatAppearance.MouseOverBackColor = Color.Wheat;
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            if (base.Checked)
            {
                base.FlatAppearance.MouseOverBackColor = base.FlatAppearance.CheckedBackColor;
            }
            else
            {
                base.FlatAppearance.MouseOverBackColor = Color.FromKnownColor(KnownColor.Control);
            }
        }

        protected override void OnCheckedChanged(EventArgs e)
        {
            base.OnCheckedChanged(e);

            if (base.Checked)
            {
                base.BackColor = base.FlatAppearance.CheckedBackColor;
                base.FlatAppearance.MouseOverBackColor = base.FlatAppearance.CheckedBackColor;
            }
            else
            {
                base.BackColor = Color.FromKnownColor(KnownColor.Control);
                base.FlatAppearance.MouseOverBackColor = Color.FromKnownColor(KnownColor.Control);
            }
        }


        /// <summary>
        /// Binds a player to the control
        /// </summary>
        /// <param name="p">The player</param>
        public void SetPlayer(Player p)
        {
            if (p == null)
            {
                player = null;
                base.Text = string.Empty;
                tooltip.SetToolTip(this, null);
            }
            else
            {
                player = p;
                base.Text = p.Shirt;
                tooltip.SetToolTip(this, p.Name);
            }
        }

        /// <summary>
        /// Returns the player associated with the control
        /// </summary>
        /// <returns>'null' if no player is added, otherwise the player</returns>
        public Player GetPlayer()
        {
            return player;
        }


        /// <summary>
        /// Returns true of a player is associated with the control, otherwise false
        /// </summary>
        public bool HasPlayer
        {
            get
            {
                return player != null;
            }
        }


        /// <summary>
        /// Removes the player
        /// </summary>
        public void RemovePlayer()
        {
            player = null;
            base.Text = string.Empty;
        }
    }
}
